﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;

namespace CommonFoundation.DataModel
{
    [Serializable]
    public class Lesson
    {
        private List<Schedule> schedules = new List<Schedule>();

        public List<Schedule> Schedules
        {
            get
            {
                return this.schedules;
            }

            set
            {
                this.schedules = value;
            }
        }

        public string TeacherName
        {
            get;
            set;
        }

        public string LessonName
        {
            get;
            set;
        }

        public Lesson()
        {
        }

        private int startIndex = 13;//日程开始的序号

        public Lesson(HtmlNodeCollection infos)
        {
            //操作 课头状态	课头号	课程名	课程号	成绩类型	 学习类型	授课学院	 教师	 计划学院	 专业	 学分	 学时

            this.LessonName = infos.ElementAt(3).InnerText;

            this.TeacherName = infos.ElementAt(8).InnerText;

            this.Schedules.Clear();

            for (int i = 0; i < 7; i++)
            {
                //1-17周,每2周; 3-4节,3区,1-326

                string[] scheduleInfo = infos.ElementAt(i + this.startIndex).InnerText.Replace(';', ',').Split(',') ;

                if (scheduleInfo.Length != 5)
                {
                    continue;
                }

                Schedule schedule = new Schedule();

                schedule.Weeks = scheduleInfo[0];
                schedule.Period = scheduleInfo[1];

                schedule.Time = scheduleInfo[2];
                schedule.Location = scheduleInfo[3] + scheduleInfo[4];

                schedule.WeekDay = (i + 1) % 7;

                this.Schedules.Add(schedule);
            }
        }

        public string School
        {
            get;
            set;
        }

        public override string ToString()
        {
            return String.Format("{0}; {1}; ", this.LessonName, this.TeacherName);
        }
        
    }
}
